Published 2005-03-05 11:04:01

As part of the QA for the first release of DBDO, I'm migrating my current website from PHP4 to PHP5, while the original code ran on PHP5 with only a few minor changes (adding clone() to a few locations), Obviously there was more that could/should be done to it.
  • migrate DB_DataObject code to DBDO - which consists of.
    • add the DBDO::config() lines
    • change DB_DataObject::factory calls to DBDO::factory, and add the database alias as the first arg.
    • change find() and find(true) to query() and query();+fetch()
    • comment out the bits I havent finished yet (like escape().. - which is pretty critical)
  • replace XML_Tree with php's DOM...
The navigation code on my site uses a HTML file which is just a simple <UL> etc. and is just chopped up, a few extra tags added, then rendered with CSS when you view a page.. It was done as a proof of concept, as I really liked the single file nav concept (based off of Paul Wiki thing), but using wiki/just text and those dumb wiki DancingCaps names everywhere just sucked bigtime.
I also rather liked the idea of modifying the thing in a HTML Editor (until I could be bothered creating a real editor), so that's how the current idea came about.

To do the rendering / url rewriting, the file is passed and modified by XML_Tree and a few node iterators (good ole function calls and foreach(array_keys($node->children) as $i) ...... I've still not been convinced that PHP5 Iterators had anything other than being 'cool', I suspect they will make code less readable, and more magic.

After having done quite a bit DOM with Javascript, I made the decision to replace the XML_Tree code, with DOM, It turned out however that Javascript Implements DOM++, and PHP only impliments DOM...

The biggest difference between PHP and Javascript's DOM is that Javascript has effectivly decided to implement alot of SimpleXML's features within the DOM model. These are the differences, which I find more than a little annoying in PHP.

Fetching Children:
Javascript: child = node.childNodes[12];
PHP: $child = $node->childNodes->item(12);

Fetching Attribute value
Javascript: href = node.attributes['href']
PHP: $href = $node->getAttribute('href');

Setting Attribute value
Javascript: node.attributes['href'] = 'somevalue';
PHP: $node->getAttribute('href','somevalue');


There are a few other things that would be nice, that both miss out on.

Appending Elements

Javascript:
node = doc.createElement("span");
parent_node.appendNode(node);
PHP:
$node = $document->createElement("span");
$parent_node->appendNode($node);

PHP 'Natrual Way':
$node = new DOMElement("span"); // AFAIK this may work.
$node->childNodes[] = $node; //

From what I remember you can convert a simpleXML document to a DOM document, but It would be far better if DOM just implemented a few of SimpleXML Features..

PHP should really be about clarity, simplicity, and getting things done.. DOM is pretty close, but could really do with pushing it the last mile..



Mentioned By:
google.com : simplexml delete node (116 referals)
google.com : SimpleXML remove Child (85 referals)
google.com : simplexml remove node (84 referals)
google.com : php xml dom (75 referals)
google.com : simplexml delete (71 referals)
google.com : simplexml delete child (69 referals)
google.com : april (67 referals)
google.com : php simplexml delete node (67 referals)
google.com : simplexml remove (66 referals)
google.com : php simplexml remove node (55 referals)
google.com : php simplexml remove child (52 referals)
google.com : php childNodes (50 referals)
google.com : php simplexml delete (49 referals)
google.com : march (37 referals)
google.com : javascript appendnode (33 referals)
google.com : php xmldom (32 referals)
google.com : php simplexml remove (31 referals)
google.com : php simplexml delete child (25 referals)
www.artima.com : PHP Buzz Forum - PHP's XML DOM , almost there... (22 referals)
google.com : december (21 referals)

Comments

updates
Got a nice email from Rob Richards on this,
the objects constructors do work, however with a few cavaets (like adding children to them will not work)
$node = new DOMElement("span");

Full docs for the constructors will appear soon... in the manual

and overloading the dim[] on some list elements may appear in later versions (no promises, but it's just alot of the original effort, quite rightly so, has gone into getting the basic stuff working right.)
#0 - Alan Knowles ( Link) on 2005-03-07 13:42:32 Delete Comment

Add Your Comment

Follow us on